import serial
import time
ser = serial.Serial("/dev/ttyAMA0", 921600, bytesize=8, parity=serial.PARITY_EVEN)  #
time.sleep(5)
ser.flushInput()  #


check_stm32 = 0


def verify(data1, *data):
    check = data1
    for var in data:
        check = check + var
    check = (check+1105) % 128
    return check


def sendMsg(upDown, speedUpDown, forwardBack, speedForwardBack, direction, speedDirection, shift, shiftSpeed, POS, PIT, SpeedPIT, ROL, SpeedROL, Light, LED):
    # ser.write("0x15\r\n".encode("utf-8"))
    check_stm32 = verify(upDown, speedUpDown, forwardBack, speedForwardBack, direction, speedDirection, shift, shiftSpeed, POS, PIT, SpeedPIT, ROL, SpeedROL, Light, LED)
    msg = "AA"+chr(upDown)+chr(speedUpDown)+chr(forwardBack)+chr(speedForwardBack)+chr(direction)+chr(speedDirection)+chr(shift)+chr(shiftSpeed) +\
          chr(POS)+chr(PIT)+chr(SpeedPIT)+chr(ROL)+chr(SpeedROL)+chr(Light)+chr(LED)+chr(check_stm32)+"BByz\r\n"
    check_stm32 = 0
    ser.write(msg.encode())  # se
    ser.flushInput()  #


def hello():
    print("hello world")
